package App.Controller;

import App.Model.*;
import App.Model.Account.CrmUser;
import App.Model.Task.*;
import App.Service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.UUID;

/**
 * Created by xw on 2018/11/21.
 */

@RestController
@RequestMapping("/api/task/")
public class TaskController extends BaseController {

    @Autowired
    private TaskService _service;

    //任务列表
    @RequestMapping("list")
    public ResponseEntity<?> listTask(@RequestBody(required = false) TaskListRequest _request) {
        DataResponse _dataResponse = new DataResponse();
        try {
            List<TaskInfoList> _result = _service.getTaskList(_request, userId());
            _dataResponse.setData(_result);
        } catch (Exception ex) {
            ex.printStackTrace();
            // return null;
        }
        return new ResponseEntity(_dataResponse, HttpStatus.OK);
    }

    //任务列表
    @RequestMapping("v2/list")
    public ResponseEntity<?> listTaskV2(@RequestBody(required = false) TaskListRequest _request) {
        DataResponse _dataResponse = new DataResponse();
        try {
            if (_request == null) {
                _request = new TaskListRequest();
            }
            if (!StringUtils.hasText(_request.getSearchkey())) {
                _request.setSearchkey("");
            }
            if (_request.getPageindex() == 0) {
                _request.setPageindex(1);
            }
            if (_request.getPagesize() == 0) {
                _request.setPagesize(20);
            }
            List<TaskInfoList> _result = _service.getTaskList(_request, userId());
            _dataResponse.setData(_result);
        } catch (Exception ex) {
            ex.printStackTrace();
            // return null;
        }
        return new ResponseEntity(_dataResponse, HttpStatus.OK);
    }

    //保存，编辑任务
    @RequestMapping("save")
    public ResponseEntity<BaseResponse> saveTask(@RequestBody(required = false) TaskSaveRequest _request) {

        BaseResponse _baseResponse = ResponseError(null, "参数格式错误");
        if (_request == null) {
            return new ResponseEntity(_baseResponse, HttpStatus.OK);
        }
        try {
            String _taskid = UUID.randomUUID().toString();
            ResultResponse result = _service.insertTask(_request, _taskid, userId());
            _baseResponse.setMessage("保存失败");
            _baseResponse.setSuccess(BaseEnum.ApiResult.Failure.getApiResult());

            String _requestTaskid = _request.getTaskid();
            if (_requestTaskid != null && !_requestTaskid.isEmpty()) {
                _baseResponse.setData(_requestTaskid);
            } else {
                _baseResponse.setData(_taskid);
            }
            if (result.getResultcode() > 0) {
                _baseResponse.setMessage("保存成功");
                _baseResponse.setSuccess(BaseEnum.ApiResult.Success.getApiResult());
            } else {
                _baseResponse.setMessage(result.getMessage());
                _baseResponse.setSuccess(BaseEnum.ApiResult.Failure.getApiResult());
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return new ResponseEntity(_baseResponse, HttpStatus.OK);
    }

    //任务详情
    @RequestMapping("detail")
    public ResponseEntity<?> getTaskDetail(@RequestBody(required = false) TaskGetDetailRequest _request) {
        DataResponse _dataResponse = new DataResponse();
        try {
            TaskGetDetailResponse _detailResponse = _service.getTaskDetail(_request, userId());
            _dataResponse.setData(_detailResponse);
        } catch (Exception ex) {
            ex.printStackTrace();
            _dataResponse.setData(ex.getMessage());
        }
        return new ResponseEntity(_dataResponse, HttpStatus.OK);
    }

    //提醒重复频度类型
    @RequestMapping("repeattype")
    public ResponseEntity<?> getTaskReminderRepeatType() {
        DataResponse _dataResponse = new DataResponse();
        try {
            List<TaskRepeatType> _response = _service.getTaskRepeatTypeResponse();
            _dataResponse.setData(_response);
        } catch (Exception ex) {
            ex.printStackTrace();
            _dataResponse.setData(ex.getMessage());
        }
        return new ResponseEntity(_dataResponse, HttpStatus.OK);
    }

    //提醒提前时间类型
    @RequestMapping("aheadtype")
    public ResponseEntity<?> getAheadTypeResponse() {
        DataResponse _dataResponse = new DataResponse();
        try {
            List<TaskAheadType> _response = _service.getAheadTypeResponse();
            _dataResponse.setData(_response);
        } catch (Exception ex) {
            ex.printStackTrace();
            _dataResponse.setData(ex.getMessage());
        }
        return new ResponseEntity(_dataResponse, HttpStatus.OK);
    }

    //删除任务
    @RequestMapping("delete")
    public ResponseEntity<BaseResponse> deleteTask(@RequestBody(required = false) TaskDeleteRequest _request) {

        if (_request == null) {
            BaseResponse _baseResponse = ResponseError(null, "参数格式错误");
            return new ResponseEntity(_baseResponse, HttpStatus.OK);
        }

        int result = _service.deleteTask(_request, userId());

        BaseResponse _baseResponse = ResponseError(null, "参数格式错误");
        _baseResponse.setMessage("保存失败");
        _baseResponse.setSuccess(BaseEnum.ApiResult.Failure.getApiResult());

        if (result > 0) {
            _baseResponse.setMessage("保存成功");
            _baseResponse.setSuccess(BaseEnum.ApiResult.Success.getApiResult());
        }
        return new ResponseEntity(_baseResponse, HttpStatus.OK);
    }

    //完成任务
    @RequestMapping("complete")
    public ResponseEntity<BaseResponse> completeTask(@RequestBody(required = false) TaskCompleteRequest _request) throws Exception {

        if (_request == null) {
            BaseResponse _baseResponse = ResponseError(null, "参数格式错误");
            return new ResponseEntity(_baseResponse, HttpStatus.OK);
        }

        int result = _service.completeTask(_request, userId());

        BaseResponse _baseResponse = ResponseError(null, "参数格式错误");
        _baseResponse.setMessage("保存失败");
        _baseResponse.setSuccess(BaseEnum.ApiResult.Failure.getApiResult());

        if (result > 0) {
            _baseResponse.setMessage("保存成功");
            _baseResponse.setSuccess(BaseEnum.ApiResult.Success.getApiResult());
        }
        return new ResponseEntity(_baseResponse, HttpStatus.OK);
    }

    //暂停任务
    @RequestMapping("pause")
    public ResponseEntity<BaseResponse> pauseTask(@RequestBody(required = false) TaskPauseRequest _request) {

        if (_request == null) {
            BaseResponse _baseResponse = ResponseError(null, "参数格式错误");
            return new ResponseEntity(_baseResponse, HttpStatus.OK);
        }

        int result = _service.pauseTask(_request, userId());

        BaseResponse _baseResponse = ResponseError(null, "参数格式错误");
        _baseResponse.setMessage("保存失败");
        _baseResponse.setSuccess(BaseEnum.ApiResult.Failure.getApiResult());

        if (result > 0) {
            _baseResponse.setMessage("保存成功");
            _baseResponse.setSuccess(BaseEnum.ApiResult.Success.getApiResult());
        }
        return new ResponseEntity(_baseResponse, HttpStatus.OK);
    }

    //重启任务
    @RequestMapping("restart")
    public ResponseEntity<BaseResponse> restartTask(@RequestBody(required = false) TaskRestartRequest _request) throws Exception {

        if (_request == null) {
            BaseResponse _baseResponse = ResponseError(null, "参数格式错误");
            return new ResponseEntity(_baseResponse, HttpStatus.OK);
        }

        int result = _service.restartTask(_request, userId());

        BaseResponse _baseResponse = ResponseError(null, "参数格式错误");
        _baseResponse.setMessage("保存失败");
        _baseResponse.setSuccess(BaseEnum.ApiResult.Failure.getApiResult());

        if (result > 0) {
            _baseResponse.setMessage("保存成功");
            _baseResponse.setSuccess(BaseEnum.ApiResult.Success.getApiResult());
        }
        return new ResponseEntity(_baseResponse, HttpStatus.OK);
    }

    //转移任务管理员身份
    @RequestMapping("transfermanager")
    public ResponseEntity<BaseResponse> transferManager(@RequestBody(required = false) TaskTransferManagerRequest _request) {

        if (_request == null) {
            BaseResponse _baseResponse = ResponseError(null, "参数格式错误");
            return new ResponseEntity(_baseResponse, HttpStatus.OK);
        }

        int result = _service.transferManager(_request, userId());

        BaseResponse _baseResponse = ResponseError(null, "参数格式错误");
        _baseResponse.setMessage("保存失败");
        _baseResponse.setSuccess(BaseEnum.ApiResult.Failure.getApiResult());

        if (result > 0) {
            _baseResponse.setMessage("保存成功");
            _baseResponse.setSuccess(BaseEnum.ApiResult.Success.getApiResult());
        }
        return new ResponseEntity(_baseResponse, HttpStatus.OK);
    }

    @RequestMapping("transferhost")
    public ResponseEntity<BaseResponse> transferHost(@RequestBody(required = false) TaskTransferHostRequest _request) {

        if (_request == null) {
            BaseResponse _baseResponse = ResponseError(null, "参数格式错误");
            return new ResponseEntity(_baseResponse, HttpStatus.OK);
        }

        int result = _service.transferHost(_request, userId());

        BaseResponse _baseResponse = ResponseError(null, "参数格式错误");
        _baseResponse.setMessage("保存失败");
        _baseResponse.setSuccess(BaseEnum.ApiResult.Failure.getApiResult());

        if (result > 0) {
            _baseResponse.setMessage("保存成功");
            _baseResponse.setSuccess(BaseEnum.ApiResult.Success.getApiResult());
        }
        return new ResponseEntity(_baseResponse, HttpStatus.OK);
    }

    //把任务文件合并到项目文件夹
    @RequestMapping("filemerge")
    public ResponseEntity<BaseResponse> mergeFileToProject(@RequestBody(required = false) TaskFileMergeRequest _request) {

        if (_request == null) {
            BaseResponse _baseResponse = ResponseError(null, "参数格式错误");
            return new ResponseEntity(_baseResponse, HttpStatus.OK);
        }

        int result = _service.taskFileMerge(_request, userId());

        BaseResponse _baseResponse = ResponseError(null, "参数格式错误");
        _baseResponse.setMessage("保存失败");
        _baseResponse.setSuccess(BaseEnum.ApiResult.Failure.getApiResult());

        if (result > 0) {
            _baseResponse.setMessage("保存成功");
            _baseResponse.setSuccess(BaseEnum.ApiResult.Success.getApiResult());
        }
        return new ResponseEntity(_baseResponse, HttpStatus.OK);
    }


    //编辑任务
    @RequestMapping("saveinfo")
    public ResponseEntity<BaseResponse> saveTaskInfo(@RequestBody(required = false) SaveTaskInfoRequest _request) {

        BaseResponse _baseResponse = ResponseError(null, "参数格式错误");
        if (_request == null) {
            return new ResponseEntity(_baseResponse, HttpStatus.OK);
        }

        //请求参数容错检查
        if (_request.getBegintime() == null || _request.getBegintime().isEmpty()) {
            _baseResponse.setMessage("开始时间不能为空");
            return new ResponseEntity(_baseResponse, HttpStatus.OK);
        }
        //开始时间格式错误

        //任务内容不能为空
        if (_request.getContent() == null || _request.getContent().isEmpty()) {
            _baseResponse.setMessage("任务内容不能为空");
            return new ResponseEntity(_baseResponse, HttpStatus.OK);
        }

        //统一返回参数

        try {
            ResultResponse result = _service.saveTaskInfo(_request, userId());
            _baseResponse.setMessage("保存失败");
            _baseResponse.setSuccess(BaseEnum.ApiResult.Failure.getApiResult());
            if (result.getResultcode() > 0) {
                _baseResponse.setMessage("保存成功");
                _baseResponse.setSuccess(BaseEnum.ApiResult.Success.getApiResult());
            } else {
                _baseResponse.setMessage(result.getMessage());
                _baseResponse.setSuccess(BaseEnum.ApiResult.Failure.getApiResult());
            }
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
            ex.printStackTrace();
        }
        return new ResponseEntity(_baseResponse, HttpStatus.OK);
    }


    //保存提醒
    @RequestMapping("savereminder")
    public ResponseEntity<BaseResponse> saveTaskReminder(@RequestBody(required = false) SaveTaskReminderRequest _request) {

        BaseResponse _baseResponse = ResponseError(null, "参数格式错误");
        if (_request == null) {
            return new ResponseEntity(_baseResponse, HttpStatus.OK);
        }

        try {
            int result = _service.saveTaskReminder(_request, userId());
            _baseResponse.setMessage("保存失败");
            _baseResponse.setSuccess(BaseEnum.ApiResult.Failure.getApiResult());
            if (result > 0) {
                _baseResponse.setMessage("保存成功");
                _baseResponse.setSuccess(BaseEnum.ApiResult.Success.getApiResult());
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return new ResponseEntity(_baseResponse, HttpStatus.OK);
    }


    //某个日期下的提醒列表
    @RequestMapping("tasklist")
    public ResponseEntity<?> getTaskForSepcialDay() {
        DataResponse _dataResponse = new DataResponse();
        try {
            List<GetTaskForSpecialDayListResponse> _result = _service.getTaskForSepcialDay(userId());
            _dataResponse.setData(_result);
        } catch (Exception ex) {
            ex.printStackTrace();
            // return null;
        }
        return new ResponseEntity(_dataResponse, HttpStatus.OK);
    }


    //save member
    @RequestMapping("addmember")
    public ResponseEntity<BaseResponse> addTaskMember(@RequestBody(required = false) AddTaskMemberRequest _request) {

        BaseResponse _baseResponse = ResponseError(null, "参数格式错误");
        if (_request == null) {
            return new ResponseEntity(_baseResponse, HttpStatus.OK);
        }

        try {
            ResultResponse result = _service.addTaskMember(_request, userId());
            _baseResponse.setMessage("保存失败");
            _baseResponse.setSuccess(BaseEnum.ApiResult.Failure.getApiResult());
            if (result.getResultcode() > 0) {
                _baseResponse.setMessage("保存成功");
                _baseResponse.setSuccess(BaseEnum.ApiResult.Success.getApiResult());
            } else {
                _baseResponse.setMessage(result.getMessage());
                _baseResponse.setSuccess(BaseEnum.ApiResult.Failure.getApiResult());
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return new ResponseEntity(_baseResponse, HttpStatus.OK);
    }


    //delete member
    @RequestMapping("deletemember")
    public ResponseEntity<BaseResponse> deleteTaskMember(@RequestBody(required = false) DeleteTaskMemberRequest _request) {

        BaseResponse _baseResponse = ResponseError(null, "参数格式错误");
        if (_request == null) {
            return new ResponseEntity(_baseResponse, HttpStatus.OK);
        }

        try {
            int result = _service.deleteTaskMember(_request, userId());
            _baseResponse.setMessage("保存失败");
            _baseResponse.setSuccess(BaseEnum.ApiResult.Failure.getApiResult());

            if (result == -1) {
                _baseResponse.setMessage("不能删除管理员或者主办人");
                return new ResponseEntity(_baseResponse, HttpStatus.OK);
            } else if (result > 0) {
                _baseResponse.setMessage("保存成功");
                _baseResponse.setSuccess(BaseEnum.ApiResult.Success.getApiResult());
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return new ResponseEntity(_baseResponse, HttpStatus.OK);
    }


    //set member to be manager
    @RequestMapping("setmanager")
    public ResponseEntity<BaseResponse> setTaskManager(@RequestBody(required = false) SetTaskManagerRequest _request) {

        BaseResponse _baseResponse = ResponseError(null, "参数格式错误");
        if (_request == null) {
            return new ResponseEntity(_baseResponse, HttpStatus.OK);
        }

        try {
            int result = _service.setTaskManager(_request, userId());
            _baseResponse.setMessage("保存失败");
            _baseResponse.setSuccess(BaseEnum.ApiResult.Failure.getApiResult());
            if (result > 0) {
                _baseResponse.setMessage("保存成功");
                _baseResponse.setSuccess(BaseEnum.ApiResult.Success.getApiResult());
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return new ResponseEntity(_baseResponse, HttpStatus.OK);
    }


    //set member to host
    @RequestMapping("sethost")
    public ResponseEntity<BaseResponse> setTaskHost(@RequestBody(required = false) SetTaskManagerRequest _request) {

        BaseResponse _baseResponse = ResponseError(null, "参数格式错误");
        if (_request == null) {
            return new ResponseEntity(_baseResponse, HttpStatus.OK);
        }

        try {
            int result = _service.setTaskHost(_request, userId());
            _baseResponse.setMessage("保存失败");
            _baseResponse.setSuccess(BaseEnum.ApiResult.Failure.getApiResult());
            if (result > 0) {
                _baseResponse.setMessage("保存成功");
                _baseResponse.setSuccess(BaseEnum.ApiResult.Success.getApiResult());
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return new ResponseEntity(_baseResponse, HttpStatus.OK);
    }

    //删除文件
    @RequestMapping("deletefile")
    public ResponseEntity<BaseResponse> deleteTaskFile(@RequestBody(required = false) TaskDeleteFileRequest _request) {

        BaseResponse _baseResponse = ResponseError(null, "参数格式错误");
        if (_request == null) {
            return new ResponseEntity(_baseResponse, HttpStatus.OK);
        }

        try {
            int result = _service.deleteTaskFile(_request, userId());
            _baseResponse.setMessage("保存失败");
            _baseResponse.setSuccess(BaseEnum.ApiResult.Failure.getApiResult());
            if (result > 0) {
                _baseResponse.setMessage("保存成功");
                _baseResponse.setSuccess(BaseEnum.ApiResult.Success.getApiResult());
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return new ResponseEntity(_baseResponse, HttpStatus.OK);
    }


    //重命名文件
    @RequestMapping("renamefile")
    public ResponseEntity<BaseResponse> renameTaskFile(@RequestBody(required = false) TaskRenameFileRequest _request) {

        BaseResponse _baseResponse = ResponseError(null, "参数格式错误");
        if (_request == null) {
            return new ResponseEntity(_baseResponse, HttpStatus.OK);
        }

        try {
            int result = _service.renameTaskFile(_request, userId());
            _baseResponse.setMessage("保存失败");
            _baseResponse.setSuccess(BaseEnum.ApiResult.Failure.getApiResult());
            if (result > 0) {
                _baseResponse.setMessage("保存成功");
                _baseResponse.setSuccess(BaseEnum.ApiResult.Success.getApiResult());
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return new ResponseEntity(_baseResponse, HttpStatus.OK);
    }


    @RequestMapping("addfile")
    public ResponseEntity<BaseResponse> addTaskFile(@RequestBody(required = false) TaskAddFileRequest _request) {

        BaseResponse _baseResponse = ResponseError(null, "参数格式错误");
        if (_request == null) {
            return new ResponseEntity(_baseResponse, HttpStatus.OK);
        }

        try {
            int result = _service.addTaskFile(_request, userId());
            _baseResponse.setMessage("保存失败");
            _baseResponse.setSuccess(BaseEnum.ApiResult.Failure.getApiResult());
            if (result > 0) {
                _baseResponse.setMessage("保存成功");
                _baseResponse.setSuccess(BaseEnum.ApiResult.Success.getApiResult());
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return new ResponseEntity(_baseResponse, HttpStatus.OK);
    }

    @RequestMapping("v2/addfile")
    public ResponseEntity<BaseResponse> addTaskFile2(@RequestBody(required = false) TaskAddFileRequest _request) {

        BaseResponse _baseResponse = ResponseError(null, "参数格式错误");
        if (_request == null) {
            return new ResponseEntity(_baseResponse, HttpStatus.OK);
        }

        try {
            int result = _service.addTaskFile2(_request, userId());
            _baseResponse.setMessage("保存失败");
            _baseResponse.setSuccess(BaseEnum.ApiResult.Failure.getApiResult());
            if (result > 0) {
                _baseResponse.setMessage("保存成功");
                _baseResponse.setSuccess(BaseEnum.ApiResult.Success.getApiResult());
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return new ResponseEntity(_baseResponse, HttpStatus.OK);
    }

    //编辑任务开始时间
    @RequestMapping("savebegintime")
    public ResponseEntity<BaseResponse> saveTaskInfoBeginTime(@RequestBody(required = false) SaveTaskBeginTimeRequest _request) {

        BaseResponse _baseResponse = ResponseError(null, "参数格式错误");
        if (_request == null) {
            return new ResponseEntity(_baseResponse, HttpStatus.OK);
        }

        //请求参数容错检查
        if (_request.getBegintime() == null || _request.getBegintime().isEmpty()) {
            _baseResponse.setMessage("开始时间不能为空");
            return new ResponseEntity(_baseResponse, HttpStatus.OK);
        }

        try {
            int result = _service.updateTaskBeginTime(_request, userId());
            _baseResponse.setMessage("保存失败");
            _baseResponse.setSuccess(BaseEnum.ApiResult.Failure.getApiResult());
            if (result > 0) {
                _baseResponse.setMessage("保存成功");
                _baseResponse.setSuccess(BaseEnum.ApiResult.Success.getApiResult());
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return new ResponseEntity(_baseResponse, HttpStatus.OK);
    }


    //获取task下的文件
    @RequestMapping("getfiles")
    public ResponseEntity<?> getTaskFiles(@RequestBody(required = false) GetTaskFileRequest _request) {
        DataResponse _dataResponse = new DataResponse();
        try {
            List<TaskFile> _result = _service.getTaskFiles(_request, userId());
            _dataResponse.setData(_result);
        } catch (Exception ex) {
            ex.printStackTrace();
            // return null;
        }
        return new ResponseEntity(_dataResponse, HttpStatus.OK);
    }

    //任务列表
    @RequestMapping("page")
    public ResponseEntity<?> getTaskPageItems(@RequestBody(required = false) GetTaskPageItemsRequest _request) {
        DataResponse _dataResponse = new DataResponse();
        try {
            GetTaskPageItemsResponse _result = _service.getTaskPageItems(_request, userId());
            _dataResponse.setData(_result);
        } catch (Exception ex) {
            ex.printStackTrace();
            // return null;
        }
        return new ResponseEntity(_dataResponse, HttpStatus.OK);
    }


    //任务列表
    @RequestMapping("uncompleted")
    public ResponseEntity<?> getUnCompletedTasks(@RequestBody(required = false) TaskListRequest _request) {
        DataResponse _dataResponse = new DataResponse();
        try {
            List<TaskInfo> _result = _service.getUnCompletedTasks(_request, userId());
            _dataResponse.setData(_result);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return new ResponseEntity(_dataResponse, HttpStatus.OK);
    }

    @RequestMapping("viewfile")
    public ResponseEntity<?> setFileViewed(@RequestBody(required = false) TaskViewdFileRequest _request) {
        BaseResponse _baseResponse = ResponseError(null, "参数格式错误");
        if (_request == null) {
            return new ResponseEntity(_baseResponse, HttpStatus.OK);
        }
        try {
            int _result = _service.setFileViewed(_request, userId());
            _baseResponse.setMessage("保存失败");
            _baseResponse.setSuccess(BaseEnum.ApiResult.Failure.getApiResult());

            if (_result > 0) {
                _baseResponse.setMessage("保存成功");
                _baseResponse.setSuccess(BaseEnum.ApiResult.Success.getApiResult());
            }
            return new ResponseEntity(_baseResponse, HttpStatus.OK);

        } catch (Exception ex) {
            ex.printStackTrace();
            _baseResponse.setMessage("保存失败");
            _baseResponse.setData(ex.getMessage());
            _baseResponse.setSuccess(BaseEnum.ApiResult.Failure.getApiResult());
        }
        return new ResponseEntity(_baseResponse, HttpStatus.OK);
    }

    @RequestMapping("delfinishedtaskgroup")
    public ResponseEntity<?> delFinishedTaskGroup(@RequestBody(required = false) CrmUser _request) {
        BaseResponse _baseResponse = ResponseError(null, "参数格式错误");
        if (_request == null) {
            return new ResponseEntity(_baseResponse, HttpStatus.OK);
        }
        try {
            int _result = _service.delFinishedTaskGroup(_request, userId());
            _baseResponse.setMessage("保存失败");
            _baseResponse.setSuccess(BaseEnum.ApiResult.Failure.getApiResult());

            if (_result > 0) {
                _baseResponse.setMessage("保存成功");
                _baseResponse.setSuccess(BaseEnum.ApiResult.Success.getApiResult());
            }
            return new ResponseEntity(_baseResponse, HttpStatus.OK);

        } catch (Exception ex) {
            ex.printStackTrace();
            _baseResponse.setMessage("保存成功");
            _baseResponse.setData(ex.getMessage());
            _baseResponse.setSuccess(BaseEnum.ApiResult.Failure.getApiResult());
        }
        return new ResponseEntity(_baseResponse, HttpStatus.OK);
    }

    //end of class
}
